// patrolnpc.txt
// Creature attacks anything it hates nearby, and spends the rest of its time patrolling a path.
// Once it has won, it returns to its home.
// Memory Cells:
//   Cell 0 - Number of path to follow.
//	 Cell 1 - If 0, just loops around path. If 1, walks to end of path, waits a little, and returns home.
//      If 2, goes to end of path and just stops.
//   Cell 2 - Node if talked to. 0 means no conversation
//   Cell 3,4 - Stuff done flag. If both 0, nothing. Otherwise when this is killed, set to 1.

begincreaturescript;

variables;

short i,target;
short reached_pt = 0;

body;

beginstate INIT_STATE;
	set_name(ME,"Terrified Servile");
	set_courage(ME,0);
	set_level(ME,3);
	
	if (gf(0,1) > 0)
		erase_char(ME);
	break;

beginstate DEAD_STATE;
	inc_flag(0,9,1);
break;

beginstate START_STATE;
	if (gf(0,8) == 0)
		end();
	if (reached_pt == 0) {
		approach_nav_point(ME,2,2);
		if (dist_to_nav_point(ME,2) <= 2)
			reached_pt = 1;
		}
		
	if (get_foe_target(ME,6,0)) {
		set_state(3);
		}
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		set_state(3);
		}
	
	if (gf(0,10) >= 10) {
		set_name(ME,"Relieved Servile");
		
		if (get_ran(1,0,100) < 5)
			create_text_bubble("Brrrrr!");
		if (get_ran(1,0,100) < 5)
			create_text_bubble("I'm scared.");
		if (get_ran(1,0,100) < 5)
			create_text_bubble("Rogues! All the rogues!");
		if (get_ran(1,0,100) < 5)
			create_text_bubble("I'm hungry.");
		}
		
	fidget(ME,15);

	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking
	if (target_ok() == FALSE)
		set_state(START_STATE);
	if (can_see_char(get_target()) == FALSE) {
		set_foe_target(ME,-1);
		set_state(START_STATE);
		}
	create_text_bubble("Eeeeeee!!!");
	flee_char(ME,get_target(),6);
break;

beginstate TALKING_STATE;
	begin_talk_mode(47);	
break;